#include "detection_bpu.h"
using namespace std;


int main()
{

    std::string model_path = "./yolov8n_instance_seg_bayese_640x640_nv12_modified_me.bin";
    std::string img_path = "./bus.jpg";
    std::string img_path1 = "./kite.jpg";
    cv::Mat input_img = cv::imread(img_path);
    cv::Mat input_img1 = cv::imread(img_path1);


    std::cout << "input_IMG: " << input_img.channels() << " ," << input_img.rows << ", " << input_img.cols << std::endl;

    BPU_Detect bpu_det(model_path);

    auto begin_time = std::chrono::system_clock::now();

    int loop_time = 500;
    for(int i = 0; i <loop_time; i++)
    {
        std::cout << "=============== INFER " << i << " ====================" << std::endl;
        if(i % 2 == 0)
        {
            bpu_det.Infer(input_img);
        }
        else
        {
            bpu_det.Infer(input_img1);
        }
        SegRes res = bpu_det.ObtainRes();

        for(int idx = 0; idx < res.detect_num; idx++)
        {
            std::cout << "Object " << idx+1 << ":" << " " << res.classes_ids[idx]<< ", ";
            std::cout << "scores=" << std::fixed << std::setprecision(4) << res.scores[idx] << " ",
            std::cout << "box=(" << res.bboxes[idx].x << ", " << res.bboxes[idx].y << ", " << res.bboxes[idx].width << ", " << res.bboxes[idx].height << std::endl;
            std::string filename = "mask_" + std::to_string(i) + "_" + std::to_string(idx) + ".png";
            // cv::imwrite(filename, res.maskes[idx]);

        } 


        // cv::Mat res = bpu_det.DrawResults();
        // std::string filename = "result_" + std::to_string(i) + ".png";
        // cv::imwrite(filename, res);
    }

    auto end_time = std::chrono::system_clock::now();


    std::chrono::duration<double> elapsed_seconds = end_time - begin_time;

    std::cout << "Elapsed time------------------------: " << elapsed_seconds.count() / loop_time * 1000 << " mseconds\n";


}